$OpenBSD: patch-util_rarian-sk-update_in,v 1.5 2015/07/25 04:25:57 ajacoutot Exp $

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=186879

Only GNU getopt supports long options.

--- util/rarian-sk-update.in.orig	Mon Sep  1 20:40:21 2008
+++ util/rarian-sk-update.in	Thu Jul 23 08:45:14 2015
@@ -19,13 +19,13 @@
 prefix=@prefix@
 exec_prefix=@exec_prefix@
 bindir=@bindir@
-statedir=@localstatedir@/lib/rarian
+statedir=@localstatedir@/db/rarian
 convert_dir=@CONVERT_DIR@
 datarootdir=@datarootdir@
 datadir=@datadir@
 output_dir=${datadir}/help
 package_version=@PACKAGE_VERSION@
-real_convert[0]=$convert_dir
+real_convert=$convert_dir
 skip_omf_translate=@ENABLE_OMF_READ@
 
 # Print the version info for this file
@@ -57,7 +57,7 @@ print_usage()
 	echo -e "\t\t\t\tscrolls.  If the directory doesn't exist, it"
 	echo -e "\t\t\t\twill be created at run time."
 	echo -e "\t\t\t\t Note: Multiple output paths are not supported"
-	echo -e "--c\t\t\t\tRebuild the index entirely.  This will rebuild"
+	echo -e "-c\t\t\t\tRebuild the index entirely.  This will rebuild"
 	echo -e "\t\t\t\tall scroll files and may take a long time."
 	echo -e "-v\t\t\t\tTurn Verbosity on."
 	echo -e "-p\t\t\t\tSpecify a different place to store the mtimes file."
@@ -97,7 +97,7 @@ process_dir()
 	for f in $1/*.omf; do
 	    bname=$(basename $f)
 	    bname=${bname%-*.omf}
-		if [[ $bname != $old_basename ]]
+		if [ $bname != $old_basename ]
 		then
 			old_basename=$bname
 	    	filename=$bname.document
@@ -112,41 +112,24 @@ process_dir()
 		    fi
 		fi
 	done
-	echo -e `stat -c %Y $1`':@:'$1':@:'$fname_list >> $tmpdir/rarian-updates
+	echo -e `stat -f %Y $1`':@:'$1':@:'$fname_list >> $tmpdir/rarian-updates
 }
 
-# Split up the omf dirs specified on the command line
-# I've never seen this used in practice, but
-# better safe than sorry
-split_omf_dirs ()
-{
-	let counter=0
-	while [ $convert_dir ]
-	do
-		entry=`echo $convert_dir | cut -d ':' -f 1`
-		convert_dir=${convert_dir#$entry}
-		convert_dir=${convert_dir#:}
-		real_convert[$counter]=$entry
-		let counter+=1
-	done
-
-}
-
 # Determine whether the directory defined within the index file
 # was specified in the convert_dirs
 am_adding_dir ()
 {
-	let counter=0
 	am_processing="0"
-	for i in ${real_convert[@]}
+	tmplist=
+	for i in ${real_convert}
 	do
-		if [[ $fname == $i ]]
+		if [ $fname == $i ]
 		then
 			real_convert[$counter]="0"
 			am_processing="1"
-			return
+		else
+			tmplist="$tmplist $i"
 		fi
-		let counter+=1
 	done
 }
 
@@ -156,7 +139,7 @@ skip_directory ()
 {
 	read line
 	time=`echo $line | awk -F ":@:" '{print $1}'`
-	while [[ $time -ne 0 ]]
+	while [ $time -ne 0 ]
 	do
 		echo $line
 		echo $line >> $tmpdir/rarian-updates
@@ -183,18 +166,18 @@ add_all_files ()
 # If the given directory actually exists within the omf dir
 dirs_contains ()
 {
-	let counter=0
 	am_processing="0"
-	for i in ${entries[@]}
+	tmplist=
+	for i in ${entries}
 	do
-		if [[ $1 == $i ]]
+		if [ $1 == $i ]
 		then
-			entries[$counter]="0"
 			am_processing="1"
-			return
+		else
+			tmplist="$tmplist $i"
 		fi
-		let counter+=1
 	done
+	entries=$tmplist
 }
 
 # The meat.  Goes through and checks each directory mtime against the
@@ -202,27 +185,26 @@ dirs_contains ()
 # If the dir has been removed, delete.
 process_directory ()
 {
-	let counter=0
+	entries=
 	for i in  $(ls $fname)
 	do
-		entries[$counter]="$fname/$i"
-		let counter+=1
+		entries="$entries $fname/$i"
 	done
 
 	read line
 
 	old_time=`echo $line | awk -F ":@:" '{print $1}'`
 
-	while [[ $old_time && $old_time != "0" ]]
+	while [ $old_time && $old_time != "0" ]
 	do
 		name=`echo $line | awk -F ":@:" '{print $2}'`
 
 		dirs_contains $name
 
-		if [[ $am_processing != "0" ]]
+		if [ $am_processing != "0" ]
 		then
-			new_time=`stat -c %Y $name`
-			if [[ $new_time -ne $old_time ]]
+			new_time=`stat -f %Y $name`
+			if [ $new_time -ne $old_time ]
 			then
 				print_verbose "Directory $name has changed.  Updating."
 				process_dir $name
@@ -231,7 +213,7 @@ process_directory ()
 			fi
 		else
 			filenames=`echo $line | awk -F ":@:" '{print $3}'`
-			while [[ $filenames ]]
+			while [ $filenames ]
 			do
 				entry=`echo $filenames | cut -d ';' -f 1`
 				print_verbose "Directory resonsible for $entry has been removed.  Deleting"
@@ -246,13 +228,10 @@ process_directory ()
 		old_time=`echo $line | awk -F ":@:" '{print $1}'`
 	done
 
-	for i in ${entries[@]}
+	for i in ${entries}
 	do
-		if [[ $i != "0" ]]
-		then
-			print_verbose "Directory $i is new and will be added."
-			process_dir $i
-		fi
+		print_verbose "Directory $i is new and will be added."
+		process_dir $i
 	done
 }
 
@@ -264,9 +243,7 @@ process_directory ()
 # They are inherited from scrollkeeper :(
 
 # We use TEMP as set -- seems to nuke the return value of getopt
-TEMP=`getopt -u -n$(basename $0) -o "o:r:p:vqnhV" \
-    	     -- "$@"` \
-    || print_usage
+TEMP=`getopt "o:r:p:cvqnhV" "$@"`
 
 if [ $? != 0 ] ; then
 	print_usage
@@ -326,7 +303,10 @@ fi
 if [ $skip_omf_translate = 0 ]
 then
 
-split_omf_dirs
+# Split up the omf dirs specified on the command line
+# I've never seen this used in practice, but
+# better safe than sorry
+real_convert=$(echo $convert_dir | sed 's/:/ /g')
 
 if [ $update_output_dir ] && [ ! $overload_update ]
 then
@@ -334,7 +314,7 @@ then
     # omf files in <prefix>/share/omf
     # Also assumes only a single omf path
     print_verbose "Using non-installed location"
-    output_dir=`dirname $real_convert[0]`/help
+    output_dir=$(dirname $(echo $real_convert | cut -d ' ' -f 1))/help
 fi
 
 print_verbose "Outputting to $output_dir"
@@ -378,16 +358,16 @@ read line
 fname=`echo $line | awk -F ":@:" '{print $2}'`
 
 
-while [[ $fname != "" ]]
+while [ $fname != "" ]
 do
 	print_verbose "Processing directory $fname"
 	echo "0:@:$fname" >> $tmpdir/rarian-updates
 	am_adding_dir $fname
-	if [[ ! $(ls $fname 2>&1) ]]
+	if [ ! $(ls $fname 2>&1) ]
 	then
 	    print_verbose "Previous directory $fname no longer exists"
 	else
-	    if [[ $am_processing != "0" ]]
+	    if [ $am_processing != "0" ]
 	    then
 		process_directory
 	    else
@@ -397,22 +377,18 @@ do
 	fi
 done
 
-for i in ${real_convert[@]}
+for i in ${real_convert}
 do
-    if [[ $i != "0" ]]
-    then
 	res=$(ls $i 2>/dev/null)
-	if [[ ! $res ]]
+	if [ ! $res ]
 	then
 	    print_verbose "Path $i does not exist.  Ignoring"
 	else
-	    
 	    print_verbose "Adding contents of directory $i"
 	    fname=$i
 	    echo "0:@:$fname" >> $tmpdir/rarian-updates
 	    add_all_files
 	fi
-    fi
 done
 
 rm -f $statedir/rarian-update-mtimes
